<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加品牌</title>
</head>
<body>
<h3>添加品牌</h3>
<form action="" method="post">
    品牌名称：<input id="brandName" name="brandName"><br>
    企业名称：<input id="companyName" name="companyName"><br>
    排序：<input id="ordered" name="ordered"><br>
    描述信息：<textarea rows="5" cols="20" id="descript" name="description"></textarea><br>
    状态：
    <input type="radio" name="status" value="0">禁用
    <input type="radio" name="status" value="1">启用<br>

    <input type="button" id="btn" value="提交">
</form>

<script src="js/axios-0.18.0.js"></script>
<script>
    document.getElementById("btn").addEventListener("click", () => {
        let status = document.getElementsByName("status")
        let statudata = ""
        for (let i = 0; i < status.length; i++) {
            if (status[i].checked) {
                statudata = status[i].value
            }
        }

        let data = {
            brandName: document.getElementById("brandName").value,
            companyName: document.getElementById("companyName").value,
            ordered: document.getElementById("ordered").value,
            descript: document.getElementById("descript").value,
            status: statudata
        }
        console.log(data)
        axios({
            method: 'post',
            url: "http://localhost:8080/ajax-demo/add",
            data
        }).then(res => {
            console.log(res);
            if (res.data == "success") {
                location.href = "http://localhost:8080/ajax-demo/brand.html";
            }
        })
    })


</script>
</body>
</html>